<template>
  <div class="app-container">
    <div class="my-define-dialog-title">
      {{title}}
      <div class="my-define-dialog-title-btn">
        <i @click="cancel(false)" class="saas-iconfont saas-icon-caozuo-quanping-shousuo"></i>
      </div>
    </div>
    <el-form ref="myForm" :model="form" :label-width="labelForm.labelWidth" :label-position="labelForm.labelPosition">
      <el-row>
        <el-col :span="24">
          <el-form-item label="名称" :prop="'label'" :rules="{
                  required: true, message: '请输入菜单名称', trigger: 'change'}">
            <el-input v-model="form.label" placeholder="请输入菜单名称" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="排序序号" :prop="'SortIndex'" :rules="{
                  required: true, message: '请输入排序序号', trigger: 'change'}">
            <el-input v-model="form.SortIndex" placeholder="请输入排序序号" />
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="form.ParentId>0">
          <el-form-item label="上级目录">
            <el-select style="width: 100%;" v-model="form.ParentId" placeholder="请选择">
              <el-option v-for="item in dataList" :key="item.Id" :label="item.label" :value="item.Id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  import {
    saveMenu
  } from '@/api/system/menu'
  import defaultSettings from '@/settings'
  export default {
    name: 'menu-edit',
    props: {
      Id: {
        type: Number,
        default: 0
      },
      title: {
        type: String,
        default: ''
      },
      data: {
        type: Object,
        default: () => ({})
      },
      dataList: {
        type: Array,
        default: () => ([])
      }
    },
    data() {
      return {
        labelForm: defaultSettings.labelForm,
        form: {
          Id: 0,
        }
      }
    },
    created() {
      this.form = this.data
    },
    methods: {
      submitForm() {
        var that = this;
        this.$refs['myForm'].validate(valid => {
          if (valid) {
            saveMenu(this.form).then(res => {
              if (res.status) {
                this.$message({
                  message: this.form.Id > 0 ? '修改成功' : '新增成功',
                  type: 'success'
                })
                this.cancel(true);
              }
            })
          }
        })
      },
      cancel(reload) {
        this.$$parent(this, "doCloseMenu", reload)
      }
    }
  }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
